began_experiment_ipw <- supp_df %>% filter(all_players_finish == T, pub_official_indicator == 1) %>% mutate(group.treatment = factor(group.treatment, levels = c("random", "merit", "patronage")))

any_vign_bivariate <-lm(any_vign ~ factor(group.treatment), began_experiment_ipw, weights = ipw)
all_vign_bivariate <- lm(all_vign ~ factor(group.treatment), began_experiment_ipw, weights = ipw)
avg_vign_bivariate <- lm(avg_vign ~ factor(group.treatment), began_experiment_ipw, weights = ipw)

observations <- c(nobs(any_vign_bivariate),nobs(all_vign_bivariate),nobs(avg_vign_bivariate))

any_vign_bivariate <- coeftest(any_vign_bivariate, vcov=vcovHC(any_vign_bivariate,type="HC0"))
all_vign_bivariate <- coeftest(all_vign_bivariate, vcov=vcovHC(all_vign_bivariate,type="HC0"))
avg_vign_bivariate <- coeftest(avg_vign_bivariate, vcov=vcovHC(avg_vign_bivariate,type="HC0"))


table <- list(any_vign_bivariate, all_vign_bivariate, avg_vign_bivariate)

note_text <- paste("Beta coefficients from OLS regression. Standard errors were calculated using the Huber-White (HC0) correction. 
                   The outcomes measures are indices capturing whether public official offered Weberian responses to (1) any of the vignettes; 
                   (2) all of the vignettes; and (3) an average indexed measure of responses.")

table = stargazer(table, type = 'latex', 
                  title = "The Effect of Selection Mode on Weberianness, IPS Weights",
                  label = 'tab:weber_ipw',
                  model.names = F,
                  model.numbers = T,
                  digits = 3,
                  column.separate = c(1,1 , 1, 1, 1, 1),
                  column.labels = c("Any", "All", "Avg", "Any", "All", "Avg"),
                  dep.var.labels = NULL, 
                  add.lines = list(c("Covariates", "N", "N", "N", "Y", "Y", "Y"),
                                   c("Observations", observations)),
                  covariate.labels = c("Treatment: Merit", "Treatment: Patronage", "Intercept (Reference: Random)"),
                  
                  #star.cutoffs = c(0.05, 0.01),
                  #float.env = 'sidewaystable',
                  keep.stat = c("n"),
                  notes = NULL,
                  notes.align = 'l')

write_latex(table[-c(10, 11, 12, 18, 21, 24, 30)], note_text, './outputs/tables/table_a10.tex', .8)




